package pzc.io.folder;

import java.util.regex.Pattern;

public class FFilter {
	private int mode = 1;
	
	private int regexpOptions = -1;
	
	private String regexp = null;

	public FFilter(String regexp, int mode){
		this.regexp = regexp;
		this.mode = mode;
	}
	public FFilter(String regexp, int regexpOptions, int mode){
		this.regexp = regexp;
		this.regexpOptions = regexpOptions;
		this.mode = mode;
	}
	
	public boolean isPass(String str){
		boolean ret = false;
		
		boolean isFound = false;
		Pattern pt = null;
		if(regexpOptions < 0){
			pt = Pattern.compile(regexp);
		}else{
			pt = Pattern.compile(regexp, regexpOptions);
		}
		if(pt.matcher(str).find()){
			isFound = true;
		}
		
		if(mode == 1 && isFound){
			ret = true;
		}else if(mode == 2 && !isFound){
			ret = true;
		}
		
		return ret;
	}
}
